"""
对新增收货地址页面进行封装
"""
import time

from common.base import Base, open_browser
from page.login_pege import LoginPage, login_url


class SitePage(Base):
    """封装表现层--制作定位器"""
    user_loc = ("link text", "用户中心")
    site_loc = ("css selector", "[href *= address]")  # 收货地址按钮
    area_country_loc = ("name", "country")  # 配送区域--国家
    area_province_loc = ("id", "selProvinces_0")  # 配送区域--省份
    area_city_loc = ("name", "city")  # 配送区域--城市
    area_district_loc = ("id", "selDistricts_0")  # 配送区域--区
    consignee_loc = ("name", "consignee")  # 收货人姓名输入框
    address_loc = ("name", "address")  # 详细地址输入框
    tel_loc = ("name", "tel")  # 电话输入框
    email_loc = ("id", "email_0")  # 电子邮件地址输入框
    zipcode_loc = ("name", "zipcode")  # 邮政编码输入框
    mobile_loc = ("name", "mobile")  # 手机输入框
    submit_loc = ("name", "submit")  # 新增收货地址按钮
    delete_loc = ("name", "button")  # 删除按钮

    """封装操作层--每一个元素的操作方法都写成一个方法"""

    def user_click(self):
        """用户中心"""
        self.click(self.user_loc)
        time.sleep(3)

    def site_click(self):
        """收货地址"""
        self.click(self.site_loc)
        time.sleep(3)

    def area_country_click(self):
        """配送区域--国家"""
        self.click(self.area_city_loc)
        time.sleep(3)

    def area_province(self):
        """配送区域--省份"""
        self.random_selection(self.area_province_loc)
        time.sleep(3)

    def area_city(self):
        """配送区域--城市"""
        self.random_selection(self.area_city_loc)
        time.sleep(3)

    def area_district(self):
        """配送区域--区"""
        self.random_selection(self.area_district_loc)
        time.sleep(3)

    def input_consignee(self, consignee):
        """收货人姓名"""
        self.send_keys(self.consignee_loc, consignee)
        time.sleep(3)

    def input_address(self, address):
        """详细地址"""
        self.send_keys(self.address_loc, address)
        time.sleep(3)

    def input_tel(self, tel):
        """电话"""
        self.send_keys(self.tel_loc, tel)
        time.sleep(3)

    def input_email(self, email):
        """电子邮件地址"""
        self.send_keys(self.email_loc, email)
        time.sleep(3)

    def input_zipcode(self, zipcode):
        """邮政编码"""
        self.send_keys(self.zipcode_loc, zipcode)
        time.sleep(3)

    def input_mobile(self, mobile):
        """手机"""
        self.send_keys(self.mobile_loc, mobile)
        time.sleep(3)

    def submit_click(self):
        """新增收货地址"""
        self.click(self.submit_loc)
        time.sleep(5)


if __name__ == '__main__':
    driver = open_browser("chrome")
    time.sleep(3)
    login = LoginPage(driver)
    login.open_url(login_url)
    login.input_username("jiangpingyu")
    login.input_password("jy542649664")
    login.submit_click()
    login1 = SitePage(driver)
    login1.user_click()
    login1.site_click()
    login1.area_province()
    login1.area_city()
    login1.area_district()
    login1.input_consignee("蒋坪雨")
    login1.input_email("123456@qq.com")
    login1.input_address("源码时代")
    login1.input_zipcode("5050550")
    login1.input_tel("15185190532")
    login1.input_mobile("15723141991")
    login1.submit_click()
    login.close_browser()
